from collections.abc import Generator
from typing import Any

from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage

class DeleteThoughtProcessTool(Tool):
    def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
        """删除</think>标签及其之前的文本"""
        # 用分隔符将文本分成两部分（只分割一次）
        text = tool_parameters['text']
        parts = text.split('</think>', 1)
        # 提取输出部分并去除首尾空白
        output = parts[1].strip() if len(parts) > 1 else text.strip()

        yield self.create_text_message(output)